package com.hotel.service.impl;

import com.hotel.mapper.OrdersMapper;
import com.hotel.pojo.Orders;
import com.hotel.service.OrdersService;
import com.hotel.vo.PageResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.Date;
import java.util.List;

@Service
public class OrdersServiceImpl implements OrdersService {
    @Autowired
    private OrdersMapper ordersMapper;

    /**
     * 分页查询并且只展现前端传来的userName
     * @param pageResult
     * @return
     */
    @Override
    public PageResult OrdersList(PageResult pageResult) {
        String userName = pageResult.getUserName();
        Long total = ordersMapper.getTotal(userName);
        int size = pageResult.getPageSize();
        int start = (pageResult.getPageNum() - 1) * size;
        String query = pageResult.getQuery();
        List<Orders> rows = ordersMapper.orderListByPage(start,size,query,userName);
        return pageResult.setTotal(total).setRows(rows);
    }

    @Override
    @Transactional
    public void deleteOrders(Integer ordersId) {
        ordersMapper.deleteOrders(ordersId);
        ordersMapper.updateStatus(ordersId);
    }

    @Override
    public void addOrders(Integer id) {
        ordersMapper.addOrders(id);
        ordersMapper.deleteTemporary(id);
    }
}
